package com.example.fresheveryday.mapper;

import com.example.fresheveryday.po.CategorySaleDTO;
import com.example.fresheveryday.po.Productcategory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ll
 * @since 2023-07-05
 */
@Mapper
public interface ProductcategoryMapper extends BaseMapper<Productcategory> {
    @Select("select * from productcategory")
    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(column = "id",property = "productsdetailets",many=@Many(select = "com.example.fresheveryday.mapper.ProductMapper.getListByCategory"))
    })
    public List<Productcategory> getHomeProduct();

    @Select("select productcategory.name,sum(saleCount*price) as sale from productcategory left join product on product.categoryId = productcategory.id group by productcategory.name")
    public List<CategorySaleDTO> getByCategorySale();
}
